#include "Backdrop.h"
#include "texturelibrary.h"
#include <iostream>

void BackDrop :: MakeSprites()
{
	sf::Texture *backTexture = NULL;
	backTexture = TT::TextureLibrary[imageFilename];
	// Make a sprite and set its origin:
	if (backTexture != NULL)
	{
		Backdrop1 = sf::Sprite(*backTexture);
		Backdrop2 = sf::Sprite(*backTexture);
		Backdrop1.setScale(sf::Vector2f(backDropScale, backDropScale));
		Backdrop2.setScale(sf::Vector2f(backDropScale, backDropScale));
		backdropWidth = backTexture->getSize().x * backDropScale;
		backDrop1Pos = sf :: Vector2f(0, 0);
		backDrop2Pos = sf::Vector2f(backdropWidth, 0);
		Backdrop2.setPosition(backDrop2Pos);
	}
	else
	{
		std::cout << "ERROR: Objects texture does not exist!!" << std :: endl;
	}
};

void BackDrop::Render(sf::RenderWindow* window)
{
	Backdrop1.setPosition(backDrop1Pos);
	Backdrop2.setPosition(backDrop2Pos);
	window->draw(Backdrop1);
	window->draw(Backdrop2);
};
void BackDrop::Update(float deltaT)
{
	backDrop1Pos.x -= 100.0f * deltaT;
	backDrop2Pos.x -= 100.0f * deltaT;

	if (backDrop1Pos.x < (-backdropWidth))
		backDrop1Pos.x = backDrop2Pos.x + backdropWidth;
	if (backDrop2Pos.x < (-backdropWidth))
		backDrop2Pos.x = backDrop1Pos.x + backdropWidth;
	
};